﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Control.Dal;

namespace Control.Bus
{
    public class BusWareHouse
    {
        public int ID { get; set; }

        public int Import { get; set; }
        public int Export { get; set; }
        public DateTime Date { get; set; }
        public int Store { get; set; }
        private BusProduct prod;
        public BusProduct Prod
        {
            set { prod = value; }
            get
            {
                if (prod == null)
                    prod = new BusProduct();
                return prod;
            }
        }
        public string ProdCode
        {
            get { return Prod.ProductCode; }
        }

        public string ProdShelf
        {
            get { return prod.ShelfName; }
        }
        internal static BusWareHouse GetWHByDateAndProd(DateTime dateTime, BusProduct Prod)
        {
            BusWareHouse resuilt = new BusWareHouse();
            List<BusWareHouse> whs = new List<BusWareHouse>();
            whs = DalWareHouse.GetTonKhoByProduct(Prod);
            foreach (BusWareHouse item in whs)
            {
                if (item.Date.ToShortDateString().CompareTo(dateTime.ToShortDateString()) == 0)
                {
                    resuilt = item;
                }
                
            }
            return resuilt;

        }

        internal void UpDate()
        {
            DalWareHouse.UpDate(this);
        }

        internal void Insert()
        {
            DalWareHouse.Insert(this);
        }



        public static List<BusWareHouse> GetAll()
        {
            return DalWareHouse.GetAll();
        }

        public static List<BusWareHouse> GetByRangeDate(DateTime fromDate, DateTime toDate)
        {
            DateTime newfromDate = new DateTime((int)fromDate.Year, (int)fromDate.Month, (int)fromDate.Day, 0, 0, 1);
            DateTime newtoDate = new DateTime((int)toDate.Year, (int)toDate.Month, (int)toDate.Day, 23, 59, 59);
            return DalWareHouse.GetByRangeDate(newfromDate, newtoDate);
        }
    }
}
